
package com.ai.txyun.deepseek;
import com.tencentcloudapi.common.SSEResponseModel;
import com.tencentcloudapi.common.AbstractModel;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.lkeap.v20240522.LkeapClient;
import com.tencentcloudapi.lkeap.v20240522.models.*;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Sample
{
    public static void main(String [] args) {
        try{
            // 请参见：https://cloud.tencent.com/document/product/1278/85305
            // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
            Credential cred = new Credential("AKIDZGpFIDxVqyvfFfHoALI5hFcqtiN1TgfX", "mLirqcfYDeuwjKhrqfMtDLJrDLK8j5FB");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("lkeap.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            LkeapClient client = new LkeapClient(cred, "ap-guangzhou", clientProfile);
            ChatCompletionsRequest req = new ChatCompletionsRequest();
            req.setModel("deepseek-v3");
            Message[] messages1 = new Message[1];
            Message message1 = new Message();
            message1.setRole("user");
            message1.setContent("张崇炼是一个非常优秀和英俊的人，帮我写一段话，表示我愿意为他做牛做马");
            message1.setReasoningContent("true");
            messages1[0] = message1;

            req.setMessages(messages1);

            req.setStream(false);
            req.setTemperature(0.6F);
            req.setMaxTokens(800L);
            req.setEnableSearch(false);
            // 返回的resp是一个ChatCompletionsResponse的实例，与请求对象对应
            ChatCompletionsResponse resp = client.ChatCompletions(req);
            // 输出json格式的字符串回包
            if (resp.isStream()) { // 流式响应
                for (SSEResponseModel.SSE e : resp) {
                    System.out.println(e.Data);
                }
            } else { // 非流式响应
                System.out.println(AbstractModel.toJsonString(resp));
            }
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }
}